<template>
	<view class="user">
		<view class="user-top">
			<view class="user-top-bg"></view>
			<view class="user-top-info" @click="getuserinfo" data-eventsync="true">
				<view class="user-top-info-part">
					<view class="user-top-info-part-name">
						<view style="color: #000;font-size: 38rpx;font-weight: 500;">hi,{{userinfo.nickName}}</view>
						<view style="color: #000;font-size: 34rpx;font-weight: 400;">很高兴为您服务！</view>
					</view>
					<view style="padding: 50rpx;">
						<image :src="userinfo.avatarUrl" style="width: 128rpx;height: 128rpx; border-radius: 64rpx;">
						</image>
					</view>
				</view>
			</view>
			<view class="user-top-goods">
				<view class="user-top-goods-part">
					<view class="user-top-goods-part-connet">
						<view class="user-top-goods-part-iconpart" @click="ToOrder(1)">
							<view class="user-top-goods-part-iconpart-icon">
								<uni-badge :text=order.no_delivery absolute="rightTop" size="small">
									<image src="@/static/user/order-icon1.png" mode="widthFix"
										style="width: 64rpx;height: 72rpx;">
									</image>
								</uni-badge>

							</view>
							<view class="user-top-goods-part-iconpart-text">
								<text style="font-size: 28rpx; color: #7f7f7f;">申请中</text>
							</view>
						</view>
						<view class="user-top-goods-part-iconpart" @click="ToOrder(2)">
							<view class="user-top-goods-part-iconpart-icon">
								<uni-badge :text=order.no_pay absolute="rightTop" size="small">
									<image src="@/static/user/order-icon2.png" mode="widthFix"
										style="width: 64rpx;height: 72rpx;">
								</uni-badge>
								</image>
							</view>
							<view class="user-top-goods-part-iconpart-text">
								<text style="font-size: 28rpx; color: #7f7f7f;">待发货</text>
							</view>
						</view>
						<view class="user-top-goods-part-iconpart" @click="ToOrder(3)">
							<view class="user-top-goods-part-iconpart-icon">
								<uni-badge :text=order.no_send absolute="rightTop" size="small">
									<image src="@/static/user/order-icon3.png" mode="widthFix"
										style="width: 64rpx;height: 72rpx;">
									</image>
								</uni-badge>

							</view>
							<view class="user-top-goods-part-iconpart-text">
								<text style="font-size: 28rpx; color: #7f7f7f;">待收货</text>
							</view>
						</view>
						<view class="user-top-goods-part-iconpart" @click="ToOrder(4)">
							<view class="user-top-goods-part-iconpart-icon">
								<uni-badge :text=order.renting absolute="rightTop" size="small">
									<image src="@/static/user/order-icon4.png" mode="widthFix"
										style="width: 64rpx;height: 72rpx;">
									</image>
								</uni-badge>

							</view>
							<view class="user-top-goods-part-iconpart-text">
								<text style="font-size: 28rpx; color: #7f7f7f;">租赁中</text>
							</view>
						</view>
						<view class="user-top-goods-part-iconpart" @click="ToOrder(0)">
							<view class="user-top-goods-part-iconpart-icon">
								<uni-badge :text=all absolute="rightTop" size="small">
									<image src="@/static/user/order-icon5.png" mode="widthFix"
										style="width: 64rpx;height: 72rpx;">
									</image>
								</uni-badge>

							</view>
							<view class="user-top-goods-part-iconpart-text">
								<text style="font-size: 28rpx; color: #7f7f7f;">全部订单</text>
							</view>
						</view>

					</view>

				</view>
			</view>
		</view>
		<view class="user-coupon" @click="ToMycoupon()">
			<view class="user-coupon-img">
				<image src="@/static/user/000000.jpg" style="width: 100%; height: 100%; border-radius: 10rpx;">
				</image>
			</view>
		</view>
		<view class="user-menu">
			<view class="user-menu-part">
				<view class="user-menu-part-class" style="border-radius: 24rpx 0 0 0;" @click="ToOrder(7)">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon2.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">我要买断</text>
					</view>
				</view>
				<view class="user-menu-part-class" @click="ToOrder(4)">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon3.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">我要归还</text>
					</view>
				</view>
				<view class="user-menu-part-class" style="border-radius: 0 24rpx 0 0;" @click="ToOrder(4)">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon4.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">支付租金</text>
					</view>
				</view>
				<view class="user-menu-part-class" @click="handleBusiness">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon5.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">商家入驻</text>
					</view>
				</view>
				<view class="user-menu-part-class" @click="ToMycoupon()">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon6.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">领券中心</text>
					</view>
				</view>
				<view class="user-menu-part-class" @click="ToService()">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon7.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">帮助中心</text>
					</view>
				</view>
				<view class="user-menu-part-class" style="border-radius: 0 0 0 24rpx;" @click="ToSuggest()">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon8.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">投诉建议</text>
					</view>
				</view>
				<view class="user-menu-part-class" style="border-radius: 0 0 0 24rpx;">
					<view class="user-menu-part-class-img">
						<image src="@/static/user/mine-icon9.png" style="width: 86rpx;height: 86rpx;"></image>
					</view>
					<view class="user-menu-part-class-text">
						<text style="font-size: 28rpx; font-weight: 200;">联通5G</text>
					</view>
				</view>
			</view>
		</view>
		<view class="user-recommend">
			<view class="user-recommend-part">
				<view class="user-recommend--connet">
					<image src="@/static/user/recommend.png" style="width: 32rpx; height: 32rpx;"></image>
					<view class="user-recommend--connet-text">
						<text style="font-size: 28rpx; font-weight: 400;">为您推荐</text>
					</view>
				</view>
			</view>
		</view>
		<GoodsList :goods="goods"></GoodsList>
	</view>
</template>

<script>
	import GoodsList from "@/component/GoodsList/GoodsList.vue";
	export default {
		data() {
			return {
				userinfo: {
					avatarUrl: '../../static/touxiang.png',
					nickName: '用户昵称'
				},
				userflag: true,
				code: '',
				postUserinfo: '',
				anonymousCode: '',
				i: 1,
				goods: [],
				imgURL2: this.$imgURL2,
				order: '',
				all: '',
				params: {
					size: 1,
					pageSize: 8,
				}
			}
		},
		components: {
			GoodsList,
		},
		onLoad() {
			this.getLocalInfo();
			this.loginInit();
			this.getDataList()
		},
		methods: {
			handleBusiness() {
				uni.navigateTo({
					url: '/pagesA/business/business',
				})
			},
			loginInit() {
				uni.login({
					success: (res) => {
						console.log(res);
						this.code = res.code;
						this.anonymousCode = res.anonymousCode;
					},
				})
			},
			getOrderCount() {
				uni.request({
					url: this.$apiUrl + 'Order/getOrderCount',
					method: "POST ",
					header: {
						token: this.userinfo.token
					},
					success: (res) => {
						const order = res.data.data;
						this.order = order;
						this.all = order.renting + order.no_send + order.no_pay + order.no_delivery
					},
				})
			},
			getLocalInfo() {
				const userInfo = uni.getStorageSync("userinfo");
				if (typeof userInfo === "object" && userInfo.token) {
					this.userinfo = userInfo
					this.getOrderCount();
				} else {
					this.userflag = false
				}
			},
			handleClick(item) {
				uni.navigateTo({
					url: '/pagesA/productDetails/productDetails?goods_id=' + item.goods_id
				})
			},
			_oldVersion() {
				uni.getUserInfo({
					withCredentials: true,
					success: (res) => {
						this.postUserinfo = res;
						this.userinfo = res.userInfo;
						this.postUserinfo.code = this.code;
						this.postUserinfo.anonymousCode = this.anonymousCode;
						uni.request({
							url: this.$apiUrl + 'Auth/grantAuth',
							data: this.postUserinfo,
							method: 'POST',
							success(res) {
								uni.setStorageSync("userinfo", res.data.data)
							},
						})
					},
				})
			},
			newVersion() {
				uni.getUserProfile({
					force: true,
					success: (res) => {
						this.postUserinfo = res;
						this.userinfo = res.userInfo;
						this.postUserinfo.code = this.code;
						this.postUserinfo.anonymousCode = this.anonymousCode;
						uni.request({
							url: this.$apiUrl + 'Auth/grantAuth',
							data: this.postUserinfo,
							method: 'POST',
							success(res) {
								uni.setStorageSync("userinfo", res.data.data)
							},
						})
					}
				})
			},
			//检查版本
			_judgeVersion() {
				const basic = 2.30;
				const systemInfo = uni.getSystemInfoSync();
				const versionArray = systemInfo.SDKVersion.split(".");
				const version = versionArray[0] + "." + versionArray[1];
				version > basic ? this.newVersion() : this.oldVersion();
			},
			getuserinfo() {
				if (this.userflag) return;
				// this._judgeVersion();
				this.newVersion()
			},
			ToOrder(e) {
				uni.navigateTo({
					url: '/pagesA/order/order?type=' + e,
				})
			},
			ToMycoupon: function() {
				uni.navigateTo({
					url: '/pagesA/mycoupon/mycoupon',
				})
			},
			ToService() {
				uni.switchTab({
					url: '/pages/service/service',
				})
			},
			ToSuggest() {
				uni.navigateTo({
					url: '/pagesA/suggest/suggest4'
				})
			},
			getDataList() {
				uni.request({
					url: this.$apiUrl + 'Centre/indexList',
					method: 'GET',
					data: this.params,
					success: (res) => {
						if (res.data.status === 300) {
							return uni.showToast({
								title: res.data.msg,
								icon: "none",
							});
						} else {
							this.params.size++;
							this.goods.push(...res.data.data.data);
						}
					}
				})
			},
		},
		onReachBottom() {
			this.getDataList();
		},
		onShareAppMessage() {
			return {
				title: '挺想租 | 租好物分享新生活 我的',
				path: this.$mp.page.route,
				imageUrl: '/logo.jpg',
			}
		},
	}
</script>

<style lang="scss" scoped>
	page {
		margin: 0;
		padding: 0;
		width: 100%;
		background-color: #f7f7f7;
	}

	.user {
		width: 100%;
	}

	.user-top {
		width: 100%;
		height: 400rpx;
		margin-top: 20rpx;
	}

	.user-top-bg {
		width: 100%;
		height: 100%;
		z-index: -1;
	}

	.user-top-info {
		width: 100%;
		height: 50%;
		position: relative;
		top: -400rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-top-goods {
		width: 100%;
		height: 50%;
		position: relative;
		top: -420rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-top-info-part {
		background-color: #fff;
		width: 90%;
		height: 100%;
		display: flex;
		justify-content: space-between;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
	}

	.user-top-info-part-name {
		padding: 70rpx;
		font-size: 32rpx;
	}

	.user-top-goods-part {
		width: 90%;
		height: 80%;
		background-color: white;
		border-bottom-left-radius: 24rpx;
		border-bottom-right-radius: 24rpx;
		display: flex;
		align-items: center;

	}

	.user-top-goods-part-iconpart {
		width: 19%;
		height: 100%;
		margin-top: 20rpx;
	}

	.user-top-goods-part-iconpart-icon {
		height: 50%;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}

	.user-top-goods-part-iconpart-text {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-top-goods-part-connet {
		width: 100%;
		height: 80%;
		display: flex;
		justify-content: space-around;
	}

	.user-coupon {
		width: 100%;
		height: 300rpx;
		margin-top: -20rpx;
		margin-bottom: 16rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-coupon-img {
		width: 90%;
		height: 92%;
	}

	.user-menu {
		width: 100%;
		height: 600rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-menu-part {
		width: 90%;
		height: 100%;
		background-color: white;
		display: flex;
		justify-content: left;
		flex-wrap: wrap;
		border-radius: 24rpx;
	}

	.user-menu-part-class {
		width: 33.333%;
		height: 200rpx;
		line-height: 30%;
		border-right: #f7f7f7 solid 1rpx;
		border-bottom: #f7f7f7 solid 1rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.user-menu-part-class-img {
		width: 100%;
		height: 50%;
		padding-top: 20rpx;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}

	.user-menu-part-class-text {
		width: 100%;
		height: 20%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-recommend {
		width: 100%;
		height: 120rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.user-recommend-part {
		width: 90%;
		height: 50%;
		padding: 20rpx;
		display: flex;
		justify-content: center;
	}

	.user-recommend--connet {
		height: 100%;
		width: 33%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.user-recommend--connet-text {
		width: 128rpx;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.goods-connet-tips-part {
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
</style>